package thread;

public class Demo39 {
    private static int sum;

    public static void main(String[] args) throws InterruptedException {
        // 通过 Runnable 来计算 1 + 2 + 3 + …… + 1000
        Thread t = new Thread(() -> {
            int result = 0;
            for (int i = 1; i <= 1000 ; i++) {
                result += i;
            }
            sum = result;
            // 需要通过成员变量来获取 但是这样就会增加耦合性
        });
        t.start();
        t.join();


        System.out.println(sum);
    }
}
